"""
魔术方法演示
"""
class Student:
    name = None  # 姓名
    sex = None  # 性别
    age = None  # 年龄

    def __init__(self, name, sex, age):
        self.name = name
        self.sex = sex
        self.age = age

    # 类似java的toString方法
    def __str__(self):
        return f"Student对象,name={self.name},sex={self.sex},age={self.age}"

    def __le__(self, other):
        return self.age <= other.age

    def __lt__(self, other):
        return self.age < other.age

    def __eq__(self, other):
        return self.name == self.name

# 演示 __str__方法
stu_1 = Student("李白", "男",1000)
print(stu_1)

# 演示 __lt__方法， __le__方法
stu_1 = Student("李白", "男",1000)
stu_2 = Student("罗辑", "男",300)
print(stu_1 > stu_2)
print(stu_1 < stu_2)

# 演示 __eq__方法
stu_1 = Student("李白", "男",1000)
stu_2 = Student("李白", "男",1001)
print(stu_1 == stu_2)

